<template>
	<view style="padding-top: 2rpx;">
		<view class="group flex-between" style="margin-top: 30rpx;" v-for="(item,index) in  groupListT" :key="index">
			<view class="flex">
				<view class="">{{item.name}}</view>
				<view class="group_text">{{item.num}} {{$t('group.name1')}}</view>
			</view>
			<view class="group_right flex" v-if="item.id!=0&&item.id!=-1">
				<view class="text1" @click="showModel(2,item)">{{$t('group.name2')}}</view>
				<image src="../../static/del.png" mode="" @click="isdelshow(item)"></image>
			</view>
		</view>
		<view class="btnsub" @click="showModel(1)">{{$t('group.name3')}}</view>
		<u-overlay :show="delshow">
			<view class="showpaw">
				<view class="text">{{$t('group.name4')}}</view>
				<view class="btn flex-between">
					<view class="btn_close" @click="delshow=false">{{$t('cancel')}}</view>
					<view class="btn_sure" @click="del">{{$t('commit')}}</view>
				</view>
			</view>
		</u-overlay>
		<u-overlay :show="addshow">
			<view class="showpaw addshow">
				<view class="text">{{modelStatus==1?$t('group.name3'):$t('group.name5')}}</view>
				<u-input :placeholder="$t('group.name6')+$t('group.name7')" border="surround" v-model="delitem.name" fontSize='14'
					class="textinput"></u-input>
				<view class="btn flex-between">
					<view class="btn_close" @click="addshow=false">{{$t('cancel')}}</view>
					<view class="btn_sure" @click="sure">{{$t('commit')}}</view>
				</view>
			</view>
		</u-overlay>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				delshow: false,
				addshow: false,
				name: '',
				groupListT: [],
				delitem: {
					name: ''
				},
				modelStatus: 1,
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('group.name')
			})
		},
		onLoad() {
			this.grouping()
		},
		methods: {
			grouping() {
				this.$fun.ajax.post('butt/groupList', {}).then(res => {
					if (res.code == 1) {
						this.groupListT = res.data
					}
				})
			},
			activeGroupingItem(item, index) {
				if (this.status == 1) {
					this.activeitem = index
					uni.navigateBack({
						group_id: item.id
					})
					uni.$emit('updateData', item)
				}
			},
			showModel(status, item) {
				this.addshow = true
				this.modelStatus = status
				this.delitem = {name:""}
				if (status == 2) {
					this.delitem = item
				}
			},
			sure(e) {
				if (this.modelStatus == 1) {
					if (this.delitem.name == '') {
						this.$fun.msg(this.$t('group.name6')+this.$t('group.name7'))
						return;
					}
					this.$fun.ajax.post('butt/addGroup', {
						name: this.delitem.name,
					}).then(res => {
						if (res.code == 1) {
							this.$fun.msg(res.msg);
							this.addshow = false
							setTimeout(() => {
								this.grouping()
							}, 500)
						}
					})
				} else {
					if (this.delitem.name == '') {
						this.$fun.msg(this.$t('group.name6')+this.$t('group.name7'))
						return;
					}
					this.$fun.ajax.post('butt/addGroup', {
						name: this.delitem.name,
						id: this.delitem.id
					}).then(res => {
						if (res.code == 1) {
							this.$fun.msg(res.msg);
							this.addshow = false
							setTimeout(() => {
								this.grouping()
							}, 500)
						}
					})
				}

			},
			isdelshow(item) {
				this.delshow = true
				this.delitem = item
			},
			del() {
				this.$fun.ajax.post('butt/delGroup', {
					id: this.delitem.id
				}).then(res => {
					if (res.code == 1) {
						this.delshow = false
						this.$fun.msg(this.$t('group.name8'))
						this.grouping()
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F1EE;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.flex-between {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.group {
		width: 690rpx;
		height: 88rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
		margin: 0 auto 0;
		box-sizing: border-box;
		padding: 0 30rpx;

		&_text {
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			margin-left: 10rpx;
		}

		&_right {
			font-weight: 500;
			font-size: 28rpx;
			color: #9999FF;

			image {
				width: 36rpx;
				height: 36rpx;
				margin-left: 30rpx;
			}

			.text2 {
				color: #5990FF;
				margin-left: 30rpx;
			}
		}
	}

	.btnsub {
		width: 690rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: #5990FF;
		border-radius: 44rpx;
		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		margin: 130rpx 30rpx 0;
		position: fixed;
		bottom: 20rpx;
	}

	.showpaw {
		width: 560rpx;
		height: 224rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 40rpx 30rpx;
		box-sizing: border-box;
		position: fixed;
		top: 30%;
		left: 95rpx;
		right: 95rpx;

		.text {
			font-weight: 500;
			font-size: 30rpx;
			color: #333333;
			text-align: center;
			margin-bottom: 30rpx;
		}

		.btn {
			margin-top: 40rpx;
			display: flex;
			justify-content: space-between;

			&_close {
				width: 230rpx;
				height: 64rpx;
				border-radius: 32rpx;
				border: 2rpx solid #5990FF;
				font-weight: 500;
				font-size: 26rpx;
				color: #5990FF;
				line-height: 64rpx;
				text-align: center;
			}

			&_sure {
				width: 230rpx;
				height: 64rpx;
				border-radius: 32rpx;
				background: #5990FF;
				font-weight: 500;
				font-size: 26rpx;
				color: #FFFFFF;
				line-height: 64rpx;
				text-align: center;
			}
		}
	}

	.addshow {
		height: 320rpx;
	}
</style>